
from datetime import datetime

from sqlalchemy import BigInteger, Integer, DateTime
from sqlalchemy.orm import mapped_column

from app.initialization.init_sqlalchemy import Base
from app.utils.utils_db import generate_id, get_timestamp_ms


class BaseModel(Base):
    __abstract__ = True

    id = mapped_column(BigInteger,
                       primary_key=True,
                       default=generate_id,
                       autoincrement=False)

    is_available = mapped_column(Integer,
                                 server_default="1",
                                 default="1",
                                 nullable=False,
                                 comment="是否可用 默认1可用，0不可用")

    create_timestamp = mapped_column(BigInteger,
                                     default=get_timestamp_ms,
                                     comment="创建时间 时间戳,毫秒级")

    update_timestamp = mapped_column(BigInteger,
                                     default=get_timestamp_ms,
                                     onupdate=get_timestamp_ms,
                                     comment="更新时间 时间戳,毫秒级")

    create_time = mapped_column(DateTime,
                                default=datetime.now,
                                comment="创建时间 冗余字段，为了查看方便，不作为返回值")
    update_time = mapped_column(DateTime,
                                default=datetime.now,
                                onupdate=datetime.now,
                                comment="更新时间 冗余字段，为了查看方便，不作为返回值")

class TestBaseModel(BaseModel):
    
    __tablename__ = "test_basemodel"
    __table_args__ = {"comment": "test_basemodel"}
    